#coding=utf-8


import numpy as np
from sklearn import metrics
################################################################################################
# 准确率 召回率
def Precision_and_Recall(test, N):
    pass
################################################################################################
# Mean Square Error 均方误差
def MSE(y_true:np.ndarray,y_pred:np.ndarray):
    return np.mean((y_true-y_pred)**2)
def MSE_by_sklearn(y_true, y_pred):
    return metrics.mean_squared_error(y_true, y_pred)

# Root Mean Square Error 均方根误差
def RMSE(y_true:np.ndarray, y_pred:np.ndarray):
    return np.sqrt(MSE(y_true,y_pred))
def RMSE_by_sklearn(y_true, y_pred):
    return np.sqrt(metrics.mean_squared_error(y_true, y_pred))

# Mean Absolute Error 平均绝对误差
def MAE(y_true:np.ndarray, y_pred:np.ndarray):
    return np.mean(np.abs(y_true-y_pred))
def MAE_by_sklearn(y_true, y_pred):
    return metrics.mean_absolute_error(y_true, y_pred)
################################################################################################


if __name__ == "__main__":
    y_true1 = np.array([1.0, 5.0, 4.0, 3.0, 2.0, 5.0, -3.0])
    y_pred1 = np.array([1.0, 4.5, 3.5, 5.0, 8.0, 4.5, 1.0])
    print(type(y_pred1))
    print(MSE(y_true1,y_pred1))
    print(MSE_by_sklearn(y_true1,y_pred1))
    print(MAE(y_true1, y_pred1))
    print(MAE_by_sklearn(y_true1, y_pred1))
    print(RMSE(y_true1, y_pred1))
    print(RMSE_by_sklearn(y_true1, y_pred1))
